package com.kehutong.auth.action;

import com.kehutong.common.webchat.XmlUtil;
import org.coraframework.json.JSONObject;
import org.coraframework.logger.Logger;
import org.coraframework.logger.LoggerFactory;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.mvc.util.ReqBody;
import org.coraframework.mvc.util.RequestUtils;

import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;

@MvcAction
@ReqMapping("/app/wx")
public class WxEventAction {
	
	private static Logger logger = LoggerFactory.getLogger(WxEventAction.class);


	@ReqMapping(value="/callback/${appId}", reqBody=ReqBody.TEXT)
	public Object callback(String appId, HttpServletRequest req) throws Exception {
		final String text = RequestUtils.readText(req);
		logger.debug("text:{}", text);
		logger.info(text);

		
		JSONObject json = XmlUtil.xml2JSON(text);
		logger.info("json:"+json);
		String content = URLDecoder.decode(json.getString("Encrypt"), "UTF-8");
		logger.info("content.....{}",content);

		return Result.text("");
	}
}
